
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include "sk_t.h"

const char *  empty_puzzle=".................................................................................";
const char *  puzstart="12345678945................2.....................................................";

char * Blancs(int n,int no)
 {static char wt[]="___________________ ",
              wn[]="                    ";
              if(no)return &wn[20-n]; else return &wt[20-n];}
void Coutg9(char * zl,int x){
	for(int i=0;i<9;i++){
		cout <<zl[i];
		if(i==2 || i== 5) cout << " ";
	}
	if(x==1) {cout <<endl; return;}
	if(!x) {cout <<"\t"; return;}
}
void CoutGrid(char * zc){
	cout << endl;
	for(int i=0;i<9;i++){
		Coutg9(&zc[9*i],1);
		if(i==2 || i== 5) cout <<endl;
	}
	cout << endl;
}
char * Char27out(int w){
	static char ws[28];
	strncpy(ws ,empty_puzzle,27);
	ws[27]=0;
	for(int j=26;j>=0;j--) if(w & (1<<j))	ws[j]='1';
	return ws;
}
char * Char9out(int w){
	static char ws[10];
	strncpy(ws, empty_puzzle, 9);
	ws[9] = 0;
	for (int j = 8; j >= 0; j--) if (w & (1 << j))			ws[j] = '1';
	return ws;

}
char * Char54out(uint64_t v){
	static char ws[55];
	strcpy(ws, &empty_puzzle[27]);
	register uint64_t bit = 1;
	for (int i = 0; i < 54; i++){
		if (bit&v)ws[i] = '1';
		bit <<= 1;
	}
	return ws;
}
char * Char64out(uint64_t v){
	static char ws[65];
	strcpy(ws, &empty_puzzle[17]);
	register uint64_t bit = 1;
	for (int i = 0; i < 64; i++){
		if (bit&v)ws[i] = '1';
		bit <<= 1;
	}
	return ws;
}
char * Char2Xout(uint64_t v){
	static char ws[55];
	strcpy(ws, &empty_puzzle[27]);
	register uint64_t bit = 1;
	for (int i = 0; i < 27; i++){
		if (bit&v)ws[i] = '1';
		bit <<= 1;
	}
	v >>= 32;
	bit = 1;
	for (int i = 0; i < 27; i++){
		if (bit&v)ws[i+27] = '1';
		bit <<= 1;
	}
	return ws;
}
char * CoutGintPuzzle(GINT * t,int n ){
	static char  zout[82];
	strcpy (zout,empty_puzzle);
	if (n > 4) return 0;
	for(int i=0;i<n;i++){
		int dig=t[i].u8[1]+'1',cell=t[i].u8[0];
		if(cell>=0 && cell<81) zout[cell]=(char)dig;
	}
	return zout;
}
char * CoutGin64tPuzzle(GINT64 * t, int n){
	static char zout[82];
	strcpy(zout, empty_puzzle);
	if (n > 8) return 0;
	for (int i = 0; i<n; i++){
		int dig = t[i].u8[1] + '1', cell = t[i].u8[0];
		if (cell >= 0 && cell<81) zout[cell] = (char)dig;
	}
	return zout;
}

int AddUA64(uint64_t * t, uint32_t & nt,uint64_t ua) {// ua 2x27  + 5 bit length
	register uint64_t ua2x = ua & BIT_SET_2X;
	for (uint32_t iua = 0; iua < nt; iua++) {
		register uint64_t R = t[iua];
		if (R < ua) {// is it subset
			R &= BIT_SET_2X;
			if ((R&ua2x) == R) return 0;// we have a subset
		}
		else if (R == ua) return 0;
		else {
			for (uint32_t jua = nt; jua > iua; jua--)t[jua] = t[jua - 1];
			t[iua] = ua;// new inserted
			nt++;
			// is it a subset of a previous entry
			for (iua++; iua < nt; iua++) {
				if ((t[iua] & ua2x) == ua2x) {// we have a subset
					for (uint32_t k = iua + 1; k < nt; k++)t[k - 1] = t[k];
					nt--;
					iua--; //continue same position
				}
			}
			return 2;
		}
	}
	t[nt++] = ua;// added
	return 1;
}



int TblMult3[9] = { 0, 3, 6, 9, 12, 15, 18, 21, 24 };  // 3*i
int TblMult9[9] = { 0, 9, 18, 27, 36, 45, 54, 63, 72 };  // 9*i
int C_minirow[81] = {// TblDiv3 as 27 sub table cell to minirow 
	0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8,
	9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17,
	18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26,
};
int * Tbldiv3 = C_minirow; //i/3 eg :  mini row or digit in F
int C_row[81] = {// cell to row
	0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5,
	6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
};
int * Tblofftorow = C_row;
int C_col[81] = {
	0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8,
	0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8,
	0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8,
};
int * TblMod9 = C_col; //i%9 eg : column in block or cell to column
int C_box[81] = {
	0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2,
	3, 3, 3, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 5, 5, 5,
	6, 6, 6, 7, 7, 7, 8, 8, 8, 6, 6, 6, 7, 7, 7, 8, 8, 8, 6, 6, 6, 7, 7, 7, 8, 8, 8,
};
int * Tblofftobox = C_box;//offset to box
int C_stack[81] = {
	0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2,
	0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2,
	0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2,
};
int C_box_rel[81] = {
	0, 1, 2, 0, 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 6, 7, 8,
	0, 1, 2, 0, 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 6, 7, 8,
	0, 1, 2, 0, 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 6, 7, 8,
};
int * TblCelltoBox = C_box_rel;// relative position in the box
int C_transpose_c[81] = {
	80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
};
int C_transpose_d[81] = {
	0, 9, 18, 27, 36, 45, 54, 63, 72, 1, 10, 19, 28, 37, 46, 55, 64, 73, 2, 11, 20, 29, 38, 47, 56, 65, 74, 3, 12, 21, 30, 39, 48, 57, 66, 75, 4, 13, 22, 31, 40, 49, 58, 67, 76, 5, 14, 23, 32, 41, 50, 59, 68, 77, 6, 15, 24, 33, 42, 51, 60, 69, 78, 7, 16, 25, 34, 43, 52, 61, 70, 79, 8, 17, 26, 35, 44, 53, 62, 71, 80,
};

int C_transpose_d2[81] = {
	80, 71, 62, 53, 44, 35, 26, 17, 8, 79, 70, 61, 52, 43, 34, 25, 16, 7, 78, 69, 60, 51, 42, 33, 24, 15, 6,
	77, 68, 59, 50, 41, 32, 23, 14, 5, 76, 67, 58, 49, 40, 31, 22, 13, 4, 75, 66, 57, 48, 39, 30, 21, 12, 3,
	74, 65, 56, 47, 38, 29, 20, 11, 2, 73, 64, 55, 46, 37, 28, 19, 10, 1, 72, 63, 54, 45, 36, 27, 18, 9, 0,
};

int C_transpose_r[81] = {
	8, 17, 26, 35, 44, 53, 62, 71, 80, 7, 16, 25, 34, 43, 52, 61, 70, 79, 6, 15, 24, 33, 42, 51, 60, 69, 78,
	5, 14, 23, 32, 41, 50, 59, 68, 77, 4, 13, 22, 31, 40, 49, 58, 67, 76, 3, 12, 21, 30, 39, 48, 57, 66, 75,
	2, 11, 20, 29, 38, 47, 56, 65, 74, 1, 10, 19, 28, 37, 46, 55, 64, 73, 0, 9, 18, 27, 36, 45, 54, 63, 72,
};

int C_transpose_rm[81] = {
	72, 63, 54, 45, 36, 27, 18, 9, 0, 73, 64, 55, 46, 37, 28, 19, 10, 1, 74, 65, 56, 47, 38, 29, 20, 11, 2,
	75, 66, 57, 48, 39, 30, 21, 12, 3, 76, 67, 58, 49, 40, 31, 22, 13, 4, 77, 68, 59, 50, 41, 32, 23, 14, 5,
	78, 69, 60, 51, 42, 33, 24, 15, 6, 79, 70, 61, 52, 43, 34, 25, 16, 7, 80, 71, 62, 53, 44, 35, 26, 17, 8,
};

int C_mod27[81] = {
	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
};
int * Tbloffset = C_mod27; // giving cell to offset in a band
int C_div27[81] = {
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
};
int * TblBoard_Block = C_div27; // giving cell -> band 

int C_To128[81] = {
	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
	32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
	64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90
};

int From_128_To_81[128] = {
	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 0, 0, 0, 0,
	27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 0, 0, 0, //54 55 dummy cells mode 54 cells
	54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 0, 0, 0, 0   // 81 dummy cell  mode 81 cells
};

int  box_col_to_row[512] = {// transpose a box
00,01,010,011,0100,0101,0110,0111,02,03,012,013,0102,0103,0112,0113,
020,021,030,031,0120,0121,0130,0131,022,023,032,033,0122,0123,0132,0133,
0200,0201,0210,0211,0300,0301,0310,0311,0202,0203,0212,0213,0302,0303,0312,0313,
0220,0221,0230,0231,0320,0321,0330,0331,0222,0223,0232,0233,0322,0323,0332,0333,
04,05,014,015,0104,0105,0114,0115,06,07,016,017,0106,0107,0116,0117,
024,025,034,035,0124,0125,0134,0135,026,027,036,037,0126,0127,0136,0137,
0204,0205,0214,0215,0304,0305,0314,0315,0206,0207,0216,0217,0306,0307,0316,0317,
0224,0225,0234,0235,0324,0325,0334,0335,0226,0227,0236,0237,0326,0327,0336,0337,
040,041,050,051,0140,0141,0150,0151,042,043,052,053,0142,0143,0152,0153,
060,061,070,071,0160,0161,0170,0171,062,063,072,073,0162,0163,0172,0173,
0240,0241,0250,0251,0340,0341,0350,0351,0242,0243,0252,0253,0342,0343,0352,0353,
0260,0261,0270,0271,0360,0361,0370,0371,0262,0263,0272,0273,0362,0363,0372,0373,
044,045,054,055,0144,0145,0154,0155,046,047,056,057,0146,0147,0156,0157,
064,065,074,075,0164,0165,0174,0175,066,067,076,077,0166,0167,0176,0177,
0244,0245,0254,0255,0344,0345,0354,0355,0246,0247,0256,0257,0346,0347,0356,0357,
0264,0265,0274,0275,0364,0365,0374,0375,0266,0267,0276,0277,0366,0367,0376,0377,
0400,0401,0410,0411,0500,0501,0510,0511,0402,0403,0412,0413,0502,0503,0512,0513,
0420,0421,0430,0431,0520,0521,0530,0531,0422,0423,0432,0433,0522,0523,0532,0533,
0600,0601,0610,0611,0700,0701,0710,0711,0602,0603,0612,0613,0702,0703,0712,0713,
0620,0621,0630,0631,0720,0721,0730,0731,0622,0623,0632,0633,0722,0723,0732,0733,
0404,0405,0414,0415,0504,0505,0514,0515,0406,0407,0416,0417,0506,0507,0516,0517,
0424,0425,0434,0435,0524,0525,0534,0535,0426,0427,0436,0437,0526,0527,0536,0537,
0604,0605,0614,0615,0704,0705,0714,0715,0606,0607,0616,0617,0706,0707,0716,0717,
0624,0625,0634,0635,0724,0725,0734,0735,0626,0627,0636,0637,0726,0727,0736,0737,
0440,0441,0450,0451,0540,0541,0550,0551,0442,0443,0452,0453,0542,0543,0552,0553,
0460,0461,0470,0471,0560,0561,0570,0571,0462,0463,0472,0473,0562,0563,0572,0573,
0640,0641,0650,0651,0740,0741,0750,0751,0642,0643,0652,0653,0742,0743,0752,0753,
0660,0661,0670,0671,0760,0761,0770,0771,0662,0663,0672,0673,0762,0763,0772,0773,
0444,0445,0454,0455,0544,0545,0554,0555,0446,0447,0456,0457,0546,0547,0556,0557,
0464,0465,0474,0475,0564,0565,0574,0575,0466,0467,0476,0477,0566,0567,0576,0577,
0644,0645,0654,0655,0744,0745,0754,0755,0646,0647,0656,0657,0746,0747,0756,0757,
0664,0665,0674,0675,0764,0765,0774,0775,0666,0667,0676,0677,0766,0767,0776,0777,
};
int treverse_mini[8] = { 0,4,2,6,1,5,3,7 };
int tband_box[6] = { 07007007, 070070070, 0700700700, 0777, 0777000, 0777000000 };
int  tband_row[3] = { 0777, 0777000, 0777000000 };
int tband_box_skrink[3] = { 0111, 0222, 0444 };


//The cell indexes in each of the 9 rows, 9 columns, and 9 squares out of fss
byte cellsInGroup[27][9] =
{
	{ 0, 1, 2, 3, 4, 5, 6, 7, 8},{ 9,10,11,12,13,14,15,16,17},{18,19,20,21,22,23,24,25,26},
	{27,28,29,30,31,32,33,34,35},{36,37,38,39,40,41,42,43,44},{45,46,47,48,49,50,51,52,53},
	{54,55,56,57,58,59,60,61,62},{63,64,65,66,67,68,69,70,71},{72,73,74,75,76,77,78,79,80},
	{ 0, 9,18,27,36,45,54,63,72},{ 1,10,19,28,37,46,55,64,73},{ 2,11,20,29,38,47,56,65,74},
	{ 3,12,21,30,39,48,57,66,75},{ 4,13,22,31,40,49,58,67,76},{ 5,14,23,32,41,50,59,68,77},
	{ 6,15,24,33,42,51,60,69,78},{ 7,16,25,34,43,52,61,70,79},{ 8,17,26,35,44,53,62,71,80},
	{ 0, 1, 2, 9,10,11,18,19,20},{ 3, 4, 5,12,13,14,21,22,23},{ 6, 7, 8,15,16,17,24,25,26},
	{27,28,29,36,37,38,45,46,47},{30,31,32,39,40,41,48,49,50},{33,34,35,42,43,44,51,52,53},
	{54,55,56,63,64,65,72,73,74},{57,58,59,66,67,68,75,76,77},{60,61,62,69,70,71,78,79,80}
};

byte miniline[54][3] =
{	{ 0, 1, 2},{ 3, 4, 5},{ 6, 7, 8},{ 9,10,11},{12,13,14},{15,16,17},{18,19,20},{21,22,23},{24,25,26},
	{27,28,29},{30,31,32},{33,34,35},{36,37,38},{39,40,41},{42,43,44},{45,46,47},{48,49,50},{51,52,53},
	{54,55,56},{57,58,59},{60,61,62},{63,64,65},{66,67,68},{69,70,71},{72,73,74},{75,76,77},{78,79,80},
	{ 0, 9,18},{27,36,45},{54,63,72},{ 1,10,19},{28,37,46},{55,64,73},{ 2,11,20},{29,38,47},{56,65,74},
	{ 3,12,21},{30,39,48},{57,66,75},{ 4,13,22},{31,40,49},{58,67,76},{ 5,14,23},{32,41,50},{59,68,77},
	{ 6,15,24},{33,42,51},{60,69,78},{ 7,16,25},{34,43,52},{61,70,79},{ 8,17,26},{35,44,53},{62,71,80}
};

byte box_miniline[54][3] =
{	{ 0, 1, 2},{ 9,10,11},{18,19,20},{ 0, 9,18},{ 1,10,19},{ 2,11,20},
	{ 3, 4, 5},{12,13,14},{21,22,23},{ 3,12,21},{ 4,13,22},{ 5,14,23},
	{ 6, 7, 8},{15,16,17},{24,25,26},{ 6,15,24},{ 7,16,25},{ 8,17,26},
	{27,28,29},{36,37,38},{45,46,47},{27,36,45},{28,37,46},{29,38,47},
	{30,31,32},{39,40,41},{48,49,50},{30,39,48},{31,40,49},{32,41,50},
	{33,34,35},{42,43,44},{51,52,53},{33,42,51},{34,43,52},{35,44,53},
	{54,55,56},{63,64,65},{72,73,74},{54,63,72},{55,64,73},{56,65,74},
	{57,58,59},{66,67,68},{75,76,77},{57,66,75},{58,67,76},{59,68,77},
	{60,61,62},{69,70,71},{78,79,80},{60,69,78},{61,70,79},{62,71,80}
};

uint64_t tbl_2x_cols[9] = { 0x4020100040201, 0x8040200080402, 0x10080400100804, 
    0x20100800201008,0x40201000402010, 0x80402000804020, 
    0x100804001008040, 0x201008002010080,0x402010004020100 };
uint64_t tbl_2x_stacks[3] = { 0x1c0e07001c0e07, 0xe0703800e07038, 0x70381c0070381c0 };
uint64_t tbl_2x_stacksn[3] = { 0xffe3f1f8ffe3f1f8, 0xff1f8fc7ff1f8fc7, 0xf8fc7e3ff8fc7e3f };
//0x40201001c0e07
int tperm6[6][3]={{0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0}};// band orderall perms
                           
int tperm3[3][3]={{0,1,2},{1,2,0},{2,0,1}}; // here all boxes are in pos 1


const T128 maskLSB[129] =
{
	{ 0, 0 },
	{ 0x00000001, 0 }, { 0x00000003, 0 }, { 0x00000007, 0 }, { 0x0000000F, 0 },
	{ 0x0000001F, 0 }, { 0x0000003F, 0 }, { 0x0000007F, 0 }, { 0x000000FF, 0 },
	{ 0x000001FF, 0 }, { 0x000003FF, 0 }, { 0x000007FF, 0 }, { 0x00000FFF, 0 },
	{ 0x00001FFF, 0 }, { 0x00003FFF, 0 }, { 0x00007FFF, 0 }, { 0x0000FFFF, 0 },
	{ 0x0001FFFF, 0 }, { 0x0003FFFF, 0 }, { 0x0007FFFF, 0 }, { 0x000FFFFF, 0 },
	{ 0x001FFFFF, 0 }, { 0x003FFFFF, 0 }, { 0x007FFFFF, 0 }, { 0x00FFFFFF, 0 },
	{ 0x01FFFFFF, 0 }, { 0x03FFFFFF, 0 }, { 0x07FFFFFF, 0 }, { 0x0FFFFFFF, 0 },
	{ 0x1FFFFFFF, 0 }, { 0x3FFFFFFF, 0 }, { 0x7FFFFFFF, 0 }, { 0xFFFFFFFF, 0 },
	{ 0x00000001FFFFFFFF, 0 }, { 0x00000003FFFFFFFF, 0 }, { 0x00000007FFFFFFFF, 0 }, { 0x0000000FFFFFFFFF, 0 },
	{ 0x0000001FFFFFFFFF, 0 }, { 0x0000003FFFFFFFFF, 0 }, { 0x0000007FFFFFFFFF, 0 }, { 0x000000FFFFFFFFFF, 0 },
	{ 0x000001FFFFFFFFFF, 0 }, { 0x000003FFFFFFFFFF, 0 }, { 0x000007FFFFFFFFFF, 0 }, { 0x00000FFFFFFFFFFF, 0 },
	{ 0x00001FFFFFFFFFFF, 0 }, { 0x00003FFFFFFFFFFF, 0 }, { 0x00007FFFFFFFFFFF, 0 }, { 0x0000FFFFFFFFFFFF, 0 },
	{ 0x0001FFFFFFFFFFFF, 0 }, { 0x0003FFFFFFFFFFFF, 0 }, { 0x0007FFFFFFFFFFFF, 0 }, { 0x000FFFFFFFFFFFFF, 0 },
	{ 0x001FFFFFFFFFFFFF, 0 }, { 0x003FFFFFFFFFFFFF, 0 }, { 0x007FFFFFFFFFFFFF, 0 }, { 0x00FFFFFFFFFFFFFF, 0 },
	{ 0x01FFFFFFFFFFFFFF, 0 }, { 0x03FFFFFFFFFFFFFF, 0 }, { 0x07FFFFFFFFFFFFFF, 0 }, { 0x0FFFFFFFFFFFFFFF, 0 },
	{ 0x1FFFFFFFFFFFFFFF, 0 }, { 0x3FFFFFFFFFFFFFFF, 0 }, { 0x7FFFFFFFFFFFFFFF, 0 }, { 0xFFFFFFFFFFFFFFFF, 0 },
	{ 0xFFFFFFFFFFFFFFFF, 0x00000001 }, { 0xFFFFFFFFFFFFFFFF, 0x00000003 }, { 0xFFFFFFFFFFFFFFFF, 0x00000007 }, { 0xFFFFFFFFFFFFFFFF, 0x0000000F },
	{ 0xFFFFFFFFFFFFFFFF, 0x0000001F }, { 0xFFFFFFFFFFFFFFFF, 0x0000003F }, { 0xFFFFFFFFFFFFFFFF, 0x0000007F }, { 0xFFFFFFFFFFFFFFFF, 0x000000FF },
	{ 0xFFFFFFFFFFFFFFFF, 0x000001FF }, { 0xFFFFFFFFFFFFFFFF, 0x000003FF }, { 0xFFFFFFFFFFFFFFFF, 0x000007FF }, { 0xFFFFFFFFFFFFFFFF, 0x00000FFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x00001FFF }, { 0xFFFFFFFFFFFFFFFF, 0x00003FFF }, { 0xFFFFFFFFFFFFFFFF, 0x00007FFF }, { 0xFFFFFFFFFFFFFFFF, 0x0000FFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x0001FFFF }, { 0xFFFFFFFFFFFFFFFF, 0x0003FFFF }, { 0xFFFFFFFFFFFFFFFF, 0x0007FFFF }, { 0xFFFFFFFFFFFFFFFF, 0x000FFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x001FFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x003FFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x007FFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x00FFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x01FFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x03FFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x07FFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x0FFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFF },
	{ 0xFFFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF }, { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF },
};

const T128 maskffff = { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF };


T128 cellsInBandBMx[6] = {
	{ 0x0000000007FFFFFF, 0x0000000000000000 }, //0 band 0 rows 123
	{ 0x003FFFFFF8000000, 0x0000000000000000 }, //1 band 1 rows 456 
	{ 0xFFC0000000000000, 0x000000000001FFFF }, //2 band 2 rows 789
	{ 0x81C0E070381C0E07, 0x0000000000000703 }, //3 stack columns 123
	{ 0x0E070381C0E07038, 0x000000000000381C }, //4 stack columns 456
	{ 0x70381C0E070381C0, 0x000000000001C0E0 }, //5 stack columns 789

};


T128 cellsInHouseBMx[27] = {
	{ 0x00000000000001FF, 0x0000000000000000 }, //0 row1
	{ 0x000000000003FE00, 0x0000000000000000 }, //1
	{ 0x0000000007FC0000, 0x0000000000000000 }, //2
	{ 0x0000000FF8000000, 0x0000000000000000 }, //3
	{ 0x00001FF000000000, 0x0000000000000000 }, //4
	{ 0x003FE00000000000, 0x0000000000000000 }, //5
	{ 0x7FC0000000000000, 0x0000000000000000 }, //6
	{ 0x8000000000000000, 0x00000000000000FF }, //7
	{ 0x0000000000000000, 0x000000000001FF00 }, //8
	{ 0x8040201008040201, 0x0000000000000100 }, //9 column 1
	{ 0x0080402010080402, 0x0000000000000201 }, //10
	{ 0x0100804020100804, 0x0000000000000402 }, //11
	{ 0x0201008040201008, 0x0000000000000804 }, //12
	{ 0x0402010080402010, 0x0000000000001008 }, //13
	{ 0x0804020100804020, 0x0000000000002010 }, //14
	{ 0x1008040201008040, 0x0000000000004020 }, //15
	{ 0x2010080402010080, 0x0000000000008040 }, //16
	{ 0x4020100804020100, 0x0000000000010080 }, //17
	{ 0x00000000001C0E07, 0x0000000000000000 }, //18 box 1
	{ 0x0000000000E07038, 0x0000000000000000 }, //19
	{ 0x00000000070381C0, 0x0000000000000000 }, //20
	{ 0x0000E07038000000, 0x0000000000000000 }, //21
	{ 0x00070381C0000000, 0x0000000000000000 }, //22
	{ 0x00381C0E00000000, 0x0000000000000000 }, //23
	{ 0x81C0000000000000, 0x0000000000000703 }, //24
	{ 0x0E00000000000000, 0x000000000000381C }, //25
	{ 0x7000000000000000, 0x000000000001C0E0 }, //26
};

T128 band3xBM[6] = {
	{ 0x0000000007FFFFFF, 0x0000000000000000 }, //0 band 0 rows 123
	{ 0x07FFFFFF00000000, 0x0000000000000000 }, //1 band 1 rows 456 
	{ 0x0000000000000000, 0x0000000007FFFFFF }, //2 band 2 rows 789
	{ 0x001C0E07001C0E07, 0x00000000001C0E07 }, //3 stack columns 123
	{ 0x00E0703800E07038, 0x0000000000E07038 }, //4 stack columns 456
	{ 0x070381C0070381C0, 0x00000000070381C0 }, //5 stack columns 789

};

T128 units3xBM[27] = {
	{ 0777, 00 },	{ 0777000, 00 },	{ 0777000000, 00 },
	{ 037740000000000, 00 },	{ 037740000000000000, 00 },	{ 037740000000000000000, 00 },
	{ 00, 0777 },	{ 00, 0777000 },	{ 00, 0777000000 },
	{ 040040040001001001, 01001001 },
	{ 0100100100002002002, 02002002 },
	{ 0200200200004004004, 04004004 },
	{ 0400400400010010010, 010010010 },
	{ 01001001000020020020, 020020020 },
	{ 02002002000040040040, 040040040 },
	{ 04004004000100100100, 0100100100 },
	{ 010010010000200200200, 0200200200 },
	{ 020020020000400400400, 0400400400 },
	{ 07007007, 00 },	{ 070070070, 00 },	{ 0700700700, 00 },
	{ 0340340340000000000, 00 },	{ 03403403400000000000, 00 },	{ 034034034000000000000, 00 },
	{ 00, 07007007 },	{ 00, 070070070 },	{ 00, 0700700700 },
};

/*
*/
CELL_FIX cellsFixedData[81] = {
{ 0 , 0 , 0 , 9 , 0 , 18 , 0 , "r1c1" },{ 1 , 0 , 1 , 10 , 0 , 18 , 1 , "r1c2" },
{ 2 , 0 , 2 , 11 , 0 , 18 , 2 , "r1c3" },{ 3 , 0 , 3 , 12 , 1 , 19 , 3 , "r1c4" },
{ 4 , 0 , 4 , 13 , 1 , 19 , 4 , "r1c5" },{ 5 , 0 , 5 , 14 , 1 , 19 , 5 , "r1c6" },
{ 6 , 0 , 6 , 15 , 2 , 20 , 6 , "r1c7" },{ 7 , 0 , 7 , 16 , 2 , 20 , 7 , "r1c8" },
{ 8 , 0 , 8 , 17 , 2 , 20 , 8 , "r1c9" },{ 9 , 1 , 0 , 9 , 0 , 18 , 0 , "r2c1" },
{ 10 , 1 , 1 , 10 , 0 , 18 , 1 , "r2c2" },{ 11 , 1 , 2 , 11 , 0 , 18 , 2 , "r2c3" },
{ 12 , 1 , 3 , 12 , 1 , 19 , 3 , "r2c4" },{ 13 , 1 , 4 , 13 , 1 , 19 , 4 , "r2c5" },
{ 14 , 1 , 5 , 14 , 1 , 19 , 5 , "r2c6" },{ 15 , 1 , 6 , 15 , 2 , 20 , 6 , "r2c7" },
{ 16 , 1 , 7 , 16 , 2 , 20 , 7 , "r2c8" },{ 17 , 1 , 8 , 17 , 2 , 20 , 8 , "r2c9" },
{ 18 , 2 , 0 , 9 , 0 , 18 , 0 , "r3c1" },{ 19 , 2 , 1 , 10 , 0 , 18 , 1 , "r3c2" },
{ 20 , 2 , 2 , 11 , 0 , 18 , 2 , "r3c3" },{ 21 , 2 , 3 , 12 , 1 , 19 , 3 , "r3c4" },
{ 22 , 2 , 4 , 13 , 1 , 19 , 4 , "r3c5" },{ 23 , 2 , 5 , 14 , 1 , 19 , 5 , "r3c6" },
{ 24 , 2 , 6 , 15 , 2 , 20 , 6 , "r3c7" },{ 25 , 2 , 7 , 16 , 2 , 20 , 7 , "r3c8" },
{ 26 , 2 , 8 , 17 , 2 , 20 , 8 , "r3c9" },{ 27 , 3 , 0 , 9 , 3 , 21 , 0 , "r4c1" },
{ 28 , 3 , 1 , 10 , 3 , 21 , 1 , "r4c2" },{ 29 , 3 , 2 , 11 , 3 , 21 , 2 , "r4c3" },
{ 30 , 3 , 3 , 12 , 4 , 22 , 3 , "r4c4" },{ 31 , 3 , 4 , 13 , 4 , 22 , 4 , "r4c5" },
{ 32 , 3 , 5 , 14 , 4 , 22 , 5 , "r4c6" },{ 33 , 3 , 6 , 15 , 5 , 23 , 6 , "r4c7" },
{ 34 , 3 , 7 , 16 , 5 , 23 , 7 , "r4c8" },{ 35 , 3 , 8 , 17 , 5 , 23 , 8 , "r4c9" },
{ 36 , 4 , 0 , 9 , 3 , 21 , 0 , "r5c1" },{ 37 , 4 , 1 , 10 , 3 , 21 , 1 , "r5c2" },
{ 38 , 4 , 2 , 11 , 3 , 21 , 2 , "r5c3" },{ 39 , 4 , 3 , 12 , 4 , 22 , 3 , "r5c4" },
{ 40 , 4 , 4 , 13 , 4 , 22 , 4 , "r5c5" },{ 41 , 4 , 5 , 14 , 4 , 22 , 5 , "r5c6" },
{ 42 , 4 , 6 , 15 , 5 , 23 , 6 , "r5c7" },{ 43 , 4 , 7 , 16 , 5 , 23 , 7 , "r5c8" },
{ 44 , 4 , 8 , 17 , 5 , 23 , 8 , "r5c9" },{ 45 , 5 , 0 , 9 , 3 , 21 , 0 , "r6c1" },
{ 46 , 5 , 1 , 10 , 3 , 21 , 1 , "r6c2" },{ 47 , 5 , 2 , 11 , 3 , 21 , 2 , "r6c3" },
{ 48 , 5 , 3 , 12 , 4 , 22 , 3 , "r6c4" },{ 49 , 5 , 4 , 13 , 4 , 22 , 4 , "r6c5" },
{ 50 , 5 , 5 , 14 , 4 , 22 , 5 , "r6c6" },{ 51 , 5 , 6 , 15 , 5 , 23 , 6 , "r6c7" },
{ 52 , 5 , 7 , 16 , 5 , 23 , 7 , "r6c8" },{ 53 , 5 , 8 , 17 , 5 , 23 , 8 , "r6c9" },
{ 54 , 6 , 0 , 9 , 6 , 24 , 0 , "r7c1" },{ 55 , 6 , 1 , 10 , 6 , 24 , 1 , "r7c2" },
{ 56 , 6 , 2 , 11 , 6 , 24 , 2 , "r7c3" },{ 57 , 6 , 3 , 12 , 7 , 25 , 3 , "r7c4" },
{ 58 , 6 , 4 , 13 , 7 , 25 , 4 , "r7c5" },{ 59 , 6 , 5 , 14 , 7 , 25 , 5 , "r7c6" },
{ 60 , 6 , 6 , 15 , 8 , 26 , 6 , "r7c7" },{ 61 , 6 , 7 , 16 , 8 , 26 , 7 , "r7c8" },
{ 62 , 6 , 8 , 17 , 8 , 26 , 8 , "r7c9" },{ 63 , 7 , 0 , 9 , 6 , 24 , 0 , "r8c1" },
{ 64 , 7 , 1 , 10 , 6 , 24 , 1 , "r8c2" },{ 65 , 7 , 2 , 11 , 6 , 24 , 2 , "r8c3" },
{ 66 , 7 , 3 , 12 , 7 , 25 , 3 , "r8c4" },{ 67 , 7 , 4 , 13 , 7 , 25 , 4 , "r8c5" },
{ 68 , 7 , 5 , 14 , 7 , 25 , 5 , "r8c6" },{ 69 , 7 , 6 , 15 , 8 , 26 , 6 , "r8c7" },
{ 70 , 7 , 7 , 16 , 8 , 26 , 7 , "r8c8" },{ 71 , 7 , 8 , 17 , 8 , 26 , 8 , "r8c9" },
{ 72 , 8 , 0 , 9 , 6 , 24 , 0 , "r9c1" },{ 73 , 8 , 1 , 10 , 6 , 24 , 1 , "r9c2" },
{ 74 , 8 , 2 , 11 , 6 , 24 , 2 , "r9c3" },{ 75 , 8 , 3 , 12 , 7 , 25 , 3 , "r9c4" },
{ 76 , 8 , 4 , 13 , 7 , 25 , 4 , "r9c5" },{ 77 , 8 , 5 , 14 , 7 , 25 , 5 , "r9c6" },
{ 78 , 8 , 6 , 15 , 8 , 26 , 6 , "r9c7" },{ 79 , 8 , 7 , 16 , 8 , 26 , 7 , "r9c8" },
{ 80 , 8 , 8 , 17 , 8 , 26 , 8 , "r9c9" },
};


int C_rbc27[81] = {// row col box in 27 bf unit mode
	01001001, 01002001, 01004001, 02010001, 02020001, 02040001, 04100001, 04200001, 04400001,
	01001002, 01002002, 01004002, 02010002, 02020002, 02040002, 04100002, 04200002, 04400002,
	01001004, 01002004, 01004004, 02010004, 02020004, 02040004, 04100004, 04200004, 04400004,
	010001010, 010002010, 010004010, 020010010, 020020010, 020040010, 040100010, 040200010, 040400010,
	010001020, 010002020, 010004020, 020010020, 020020020, 020040020, 040100020, 040200020, 040400020,
	010001040, 010002040, 010004040, 020010040, 020020040, 020040040, 040100040, 040200040, 040400040,
	0100001100, 0100002100, 0100004100, 0200010100, 0200020100, 0200040100, 0400100100, 0400200100, 0400400100,
	0100001200, 0100002200, 0100004200, 0200010200, 0200020200, 0200040200, 0400100200, 0400200200, 0400400200,
	0100001400, 0100002400, 0100004400, 0200010400, 0200020400, 0200040400, 0400100400, 0400200400, 0400400400,
};
T128 cell_z3x[81] = {
	{ 040040040007007776, 01001001 }, { 0100100100007007775, 02002002 }, { 0200200200007007773, 04004004 },
	{ 0400400400070070767, 010010010 }, { 01001001000070070757, 020020020 }, { 02002002000070070737, 040040040 },
	{ 04004004000700700677, 0100100100 }, { 010010010000700700577, 0200200200 }, { 020020020000700700377, 0400400400 },
	{ 040040040007776007, 01001001 }, { 0100100100007775007, 02002002 }, { 0200200200007773007, 04004004 },
	{ 0400400400070767070, 010010010 }, { 01001001000070757070, 020020020 }, { 02002002000070737070, 040040040 },
	{ 04004004000700677700, 0100100100 }, { 010010010000700577700, 0200200200 }, { 020020020000700377700, 0400400400 },
	{ 040040040776007007, 01001001 }, { 0100100100775007007, 02002002 }, { 0200200200773007007, 04004004 },
	{ 0400400400767070070, 010010010 }, { 01001001000757070070, 020020020 }, { 02002002000737070070, 040040040 },
	{ 04004004000677700700, 0100100100 }, { 010010010000577700700, 0200200200 }, { 020020020000377700700, 0400400400 },
	{ 0340377700001001001, 01001001 }, { 0340377640002002002, 02002002 }, { 0340377540004004004, 04004004 },
	{ 03403437340010010010, 010010010 }, { 03403436740020020020, 020020020 }, { 03403435740040040040, 040040040 },
	{ 034034033740100100100, 0100100100 }, { 034034027740200200200, 0200200200 }, { 034034017740400400400, 0400400400 },
	{ 0377700340001001001, 01001001 }, { 0377640340002002002, 02002002 }, { 0377540340004004004, 04004004 },
	{ 03437343400010010010, 010010010 }, { 03436743400020020020, 020020020 }, { 03435743400040040040, 040040040 },
	{ 034033774000100100100, 0100100100 }, { 034027774000200200200, 0200200200 }, { 034017774000400400400, 0400400400 },
	{ 037700340340001001001, 01001001 }, { 037640340340002002002, 02002002 }, { 037540340340004004004, 04004004 },
	{ 037343403400010010010, 010010010 }, { 036743403400020020020, 020020020 }, { 035743403400040040040, 040040040 },
	{ 033774034000100100100, 0100100100 }, { 027774034000200200200, 0200200200 }, { 017774034000400400400, 0400400400 },
	{ 040040040001001001, 07007776 }, { 0100100100002002002, 07007775 }, { 0200200200004004004, 07007773 },
	{ 0400400400010010010, 070070767 }, { 01001001000020020020, 070070757 }, { 02002002000040040040, 070070737 },
	{ 04004004000100100100, 0700700677 }, { 010010010000200200200, 0700700577 }, { 020020020000400400400, 0700700377 },
	{ 040040040001001001, 07776007 }, { 0100100100002002002, 07775007 }, { 0200200200004004004, 07773007 },
	{ 0400400400010010010, 070767070 }, { 01001001000020020020, 070757070 }, { 02002002000040040040, 070737070 },
	{ 04004004000100100100, 0700677700 }, { 010010010000200200200, 0700577700 }, { 020020020000400400400, 0700377700 },
	{ 040040040001001001, 0776007007 }, { 0100100100002002002, 0775007007 }, { 0200200200004004004, 0773007007 },
	{ 0400400400010010010, 0767070070 }, { 01001001000020020020, 0757070070 }, { 02002002000040040040, 0737070070 },
	{ 04004004000100100100, 0677700700 }, { 010010010000200200200, 0577700700 }, { 020020020000400400400, 0377700700 },
};
